package com.cw.jeeyt.common;

import java.util.UUID;

/**
 * UUID工具类
 *
 * @author fengmq
 */
public class UUIDTool {
    private static final String APP_PREFIX = "ap";

    private static final String TASK_PREFIX = "tk";

    private static final String LOG_PREFIX = "lg";

    /**
     * Generate unique application id.
     *
     * @return
     */
    public static String generateAppId() {
        return generateUniqueId(APP_PREFIX);
    }

    /**
     * Generate unique task id.
     *
     * @return
     */

    public static String generateTaskId() {
        return generateUniqueId(TASK_PREFIX);
    }

    /**
     * Generate unique log id.
     *
     * @return
     */

    public static String generateLogId() {
        return generateUniqueId(LOG_PREFIX);
    }

    public static String generateUniqueId(String prefix) {
        String uuid = UUID.randomUUID()
            .toString()
            .replaceAll("-", "");

        return prefix == null ? uuid : (prefix + uuid).substring(0, 32);
    }

    public static String getUUID() {
        return UUID.randomUUID()
            .toString()
            .replaceAll("-", "");
    }
}
